<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class CreateWorkflowV2TemplateNodesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('workflow_v2_template_nodes', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('workflowTemplateId')->default(0)->comment('workflow_v2_templates.id');
            $table->unsignedInteger('pId')->default(0)->comment('父节点id');
            $table->unsignedInteger('nextId')->default(0)->comment('下一节点id');
            $table->unsignedInteger('prevId')->default(0)->comment('上一节点id');

            $table->string('name', 32)->default('')->comment('节点名称');
            $table->unsignedSmallInteger('businessType')->default(0)->comment('业务类型 详见WorkflowEnum');
            $table->unsignedTinyInteger('nodeType')->default(0)->comment('节点类型 1顺序 2会签 3或签 4条件');
            $table->unsignedTinyInteger('handlerType')->default(0)->comment('处理人类型 1固定id 2督导 3省总 4加盟商');
            $table->json('handlerUids')->nullable()->comment('处理人uids，仅handlerType=1有值');
            $table->unsignedInteger('cruiseTemplateId')->default(0)->comment('cruise_template.id 巡检模板id');
            $table->json('condition')->nullable()->comment('条件节点的条件 {"projectId":3,"formula":"!=","optionsValue":2} formula: =,!=,>,<,>=,<=,in,not in');
            $table->json('ccInfo')->nullable()->comment('抄送人信息');

            $table->unsignedInteger('createdAt')->default(0)->comment('创建时间');
            $table->unsignedInteger('createdByUid')->default(0)->comment('创建人');
            $table->unsignedInteger('updatedAt')->default(0)->comment('修改时间');
            $table->unsignedInteger('updatedByUid')->default(0)->comment('修改人');
            $table->tinyInteger('isDeleted')->default(0);
            $table->collation = 'utf8mb4_general_ci';
            $table->comment = '审批流v2 - 模板节点';

            $table->index('workflowTemplateId', 'idx_workflowTemplateId');
            $table->index('pId', 'idx_pId');
            $table->index('nextId', 'idx_nextId');
            $table->index('prevId', 'idx_prevId');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('workflow_v2_template_nodes');
    }
}
